﻿namespace Pathfinding
{
    using System;
    using System.Runtime.InteropServices;
    using UnityEngine;

    [StructLayout(LayoutKind.Sequential)]
    public struct Point3D
    {
        public int X;
        public int Y;
        public int Z;
        public static Point3D Zero;
        public Point3D(int X, int Y, int Z)
        {
            this.X = X;
            this.Y = Y;
            this.Z = Z;
        }

        public Point3D(Point3D p1, Point3D p2)
        {
            this.X = p1.X + p2.X;
            this.Y = p1.Y + p2.Y;
            this.Z = p1.Z + p2.Z;
        }

        static Point3D()
        {
            Zero = new Point3D(0, 0, 0);
        }

        public int GetDistanceSquared(Point3D point)
        {
            int num = this.X - point.X;
            int num2 = this.Y - point.Y;
            int num3 = this.Z - point.Z;
            return (((num * num) + (num2 * num2)) + (num3 * num3));
        }

        public bool EqualsSS(Point3D p)
        {
            return (((p.X == this.X) && (p.Z == this.Z)) && (p.Y == this.Y));
        }

        public override int GetHashCode()
        {
            object[] objArray1 = new object[] { this.X, " ", this.Y, " ", this.Z };
            return string.Concat(objArray1).GetHashCode();
        }

        public override string ToString()
        {
            object[] objArray1 = new object[] { this.X, ", ", this.Y, ", ", this.Z };
            return string.Concat(objArray1);
        }

        public override bool Equals(object obj)
        {
            return ((obj is Point3D) && (this == ((Point3D) obj)));
        }

        public static bool operator ==(Point3D one, Point3D two)
        {
            return one.EqualsSS(two);
        }

        public static bool operator !=(Point3D one, Point3D two)
        {
            return !one.EqualsSS(two);
        }

        public static Point3D operator +(Point3D one, Point3D two)
        {
            return new Point3D(one.X + two.X, one.Y + two.Y, one.Z + two.Z);
        }

        public static Point3D operator -(Point3D one, Point3D two)
        {
            return new Point3D(one.X - two.X, one.Y - two.Y, one.Z - two.Z);
        }

        public static implicit operator Vector3(Point3D v)
        {
            return new Vector3((float) v.X, (float) v.Y, (float) v.Z);
        }

        public static implicit operator Point3D(Vector3 v)
        {
            return new Point3D(Mathf.RoundToInt(v.x), Mathf.RoundToInt(v.y), Mathf.RoundToInt(v.z));
        }

        public static implicit operator Vector2(Point3D v)
        {
            return new Vector2((float) v.X, (float) v.Y);
        }

        public static implicit operator Point3D(Vector2 v)
        {
            return new Point3D(Mathf.RoundToInt(v.x), Mathf.RoundToInt(v.y), 0);
        }
    }
}

